package com.primaryAlgorithm;

/**
 * Description: 反转数组
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-09-25 23:56:45
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-09-25     张李鑫                     1.0         1.0 Version
 */
public class ReverseString {


    public static char[] reverseString(char[]s){
        int p1=0;
        int p2=s.length-1;
        while (p1<p2){
            swap(s,p1++,p2--);
        }
        return s;
    }

    public static void swap(char[] arr, int i, int j) {
        arr[i]^=arr[j];
        arr[j]^=arr[i];
        arr[i]^=arr[j];

    }

    public static void main(String[] args) {
        char [] a={'h','e','l','l','o'};
        char[] chars = reverseString(a);
        String s = new String(chars);
        System.out.println(s);
    }
}